<template>
	<view>
		<uni-search-bar placeholder="今天想吃点啥？" @confirm="search" radius="100" v-model="name" v-bind:value="name"></uni-search-bar>
		<view class="recommend">热门搜索</view>

		<view class="" v-for="item in foodList2" :key="item.name" @click="toFoodDetail(item)">
			<view class="img">
				<image :src="item.picture" mode="aspectFill"></image>
				<view class="text">
					<view class="">{{item.name}}</view>
					<view class="">{{item.collectNum}}人收藏</view>
				</view>
			</view>
		</view>
		<view class="" v-for="item in foodList4" :key="item.name" @click="toFoodDetail(item)">
			<view class="img">
				<image :src="item.picture" mode=""></image>
				<view class="text">
					<view class="">{{item.name}}</view>
					<view class="">{{item.collectNum}}人收藏</view>
				</view>
			</view>
		</view>
		<view class="" v-if="!flag">
			抱歉，暂时没有您要找的菜呢。
		</view>
	</view>
</template>

<script>
	import uniSearchBar from '@/components/uni/uni-search-bar/uni-search-bar.vue';

	
	import {
		cookbookList
	} from '@/api/ap_cookbook';
	export default {
		data() {
			return {
				name: "",
				foodList2: [],
				foodList4: {},
				flag: true,
				foodsList: []
			};
		},
		methods: {
			async search(event) {
				this.name = event.value;
				let params={}
				params.name=event.value;
				cookbookList(params).then(res=>{
					if (res.data.length === 0) {
						this.flag = false;
					}
					this.foodList2 = res.data;
				})
				
			},


			toFoodDetail(item) {

				uni.navigateTo({
					url: `/pages/fooddetail/fooddetail?id=${item.id}`
				})
			}
		},
		components: {
			uniSearchBar
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		height: 100%;
		font-family: "楷体",serif;

		.recommend {
			margin-top: 40rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #A0A0A0;
		}

		.btns {
			display: flex;
			margin-top: 40rpx;

			.btn {
				width: 120rpx;
				height: 50rpx;
				line-height: 38rpx;
				padding: 5rpx 10rpx;
				font-size: 24rpx;
				border-radius: 30rpx;
				text-align: center;
				background-color: #ffffff;
				border: 1px #FFCC66 solid;
				color: #A0A0A0;

			}
		}

		.image {
			width: 64px;
			height: 48px;
			background-size: cover;
		}

		.img {
			width: 700rpx;
			margin: 20rpx auto;

			image {
				width: 670rpx;
				height: 400rpx;
				border-radius: 16rpx;
				margin-left: 15rpx;
				background-size: cover;
			}

			.text {
				width: 670rpx;
				margin: 15rpx 0 15rpx 15rpx;
				display: flex;
				justify-content: space-between;
				font-size: 30rpx;
			}
		}
	}
</style>
